// pages/city/li-city/li-city.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		http: getApp().globalData.map
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.request({
			url: getApp().globalData.http + 'action=getShopDetail&id=' + options.id,
			success: (e) => {
				console.log(e)
				e.data.data.zhiliang=Math.floor(e.data.data.zhiliang)
				e.data.data.speeds=Math.floor(e.data.data.speeds)
				e.data.data.jgfs=Math.floor(e.data.data.jgfs)
				if(e.data.data.zhiliang==0){
					e.data.data.zhiliang=5
				}
				if(e.data.data.speeds==0){
					e.data.data.speeds=5
				}
				if(e.data.data.jgfs==0){
					e.data.data.jgfs=5
				}
				this.setData({
					data: e.data.data
				})
			}
		})
		let that=this
		wx.getLocation({
			type: 'wgs84', // 默认wgs84
			success: function(res) {
				let x_pi = (3.14159265358979324 * 3000.0) / 180.0;
				let x = res.longitude - 0.0065;
				let y = res.latitude - 0.006;
				let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
				let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
				let lngs = z * Math.cos(theta);
				let lats = z * Math.sin(theta);
				that.setData({
					lat: lats,
					lon: lngs
				})
				console.log(res)
			},
		});
	},
	onGuideTap: function(event) {
		var lat = Number(event.currentTarget.dataset.latitude);
		var lon = Number(event.currentTarget.dataset.longitude);
		var bankName = event.currentTarget.dataset.bankname;
		let x_pi = (3.14159265358979324 * 3000.0) / 180.0;
		let x = lon - 0.0065;
		let y = lat - 0.006;
		let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
		let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
		let lngs = z * Math.cos(theta);
		let lats = z * Math.sin(theta);
		wx.openLocation({
			type: 'gcj02',
			latitude: lats,
			longitude: lngs,
			name: bankName,
			scale: 18
		})
	},

})
